function update_item(id, msg, cfm){
	var ok = 1;
	if(jQuery("#qty"+id).val() == "" || !/^\d+$/.test(jQuery("#qty"+id).val())){
		jQuery('<div style="width: 100px" class="quick-alert">'+msg+'</div>')
					 .insertAfter( jQuery("#qty"+id) )
					 .fadeIn('slow')
					 .animate({opacity: 1.0}, 3000)
					 .fadeOut('slow', function() {
					   $(this).remove();
					 });
		jQuery("#qty"+id).css('border', 'red solid 1px');			 
		ok = 0;			 
	}else{
		jQuery("#qty"+id).css('border', '#7f9db9 solid 1px');
	}
	if(ok && parseInt(jQuery("#qty"+id).val()) == 0){
		delete_item(id, '');
		ok = 0;
	}
	if(ok){
		jQuery.post("index.php", { option:'com_products', task:'update_cart', id: id, qty: jQuery("#qty"+id).val() },
					function(data){
				    	if(data.msg == 'updated'){
				    		jQuery("#cart_total").html(data.total);	 
				    		jQuery("#total"+id).html(data.price);	
				    		init_cart(); 
				    	}
					}, "json"
				);
	}
}
function delete_item(id, cfm){
	var answer = 0;
	if(cfm == ''){
		answer = 1;
	}else{
		answer = confirm(cfm);
	}
	if (answer){
		jQuery.post("index.php", { option:'com_products', task:'delete_cart', id: id },
					function(data){
				    	if(data.msg == 'deleted'){
				    		jQuery("#cart_total").html(data.total);	
				    		jQuery("#row"+id).remove(); 
				    		init_cart(); 
				    	}
					}, "json"
				);
	}
}
function init_cart(){
	jQuery.post("index.php", { option:'com_products', task:'init_cart'},
		function(data){
	    	if(data){
	    		jQuery("#cartForm").html(data.cart);
	    		jQuery("#numberItems").html('  ('+data.numberItems+')');
	    	}else{
	    		jQuery("#numberItems").html('  (0)');
	    	}
	    	//jQuery("#cartForm").css('height', jQuery("#cartList").css('height'));
		}, "json"
	);
}


